<?php
class InformationController extends Controller
{
  /**
   * @var string the default layout for the views. Defaults to '//layouts/column2', meaning
   * using two-column layout. See 'protected/views/layouts/column2.php'.
   */
  public $layout = '//layouts/column2';
  
  /**
   * @return array action filters
   */
  public function filters()
  {
    return array(
      'accessControl' // perform access control for CRUD operations
    );
  }
  
  /**
   * Specifies the access control rules.
   * This method is used by the 'accessControl' filter.
   * @return array access control rules
   */
  public function accessRules()
  {
    return array(
      array(
        'allow', // allow authenticated user to perform 'create' and 'update' actions
        'actions' => array(
          'index'
        ),
        'users' => array(
          '@'
        )
      ),
      array(
        'deny', // deny all users
        'users' => array(
          '*'
        )
      )
    );
  }
  
  public function actionIndex()
  {
    $model = AdminInfo::model()->findByAttributes(array(
      'username' => 'admin'
    ));
    
    if (Yii::app()->request->isPostRequest) {
      $model->fullname     = $_POST['AdminInfo']['fullname'];
      $model->email        = $_POST['AdminInfo']['email'];
      $model->phone        = $_POST['AdminInfo']['phone'];
      $model->cell_phone   = $_POST['AdminInfo']['cell_phone'];
      $model->old_password = $_POST['AdminInfo']['old_password'];
      $model->new_password = $_POST['AdminInfo']['new_password'];
      $model->re_password  = $_POST['AdminInfo']['re_password'];
      $model->modifieddate = time();
      if ($model->validate()) {
        $model->password = !empty($_POST['AdminInfo']['new_password']) ? md5($_POST['AdminInfo']['new_password']) : $model->password;
        $model->update();
        Yii::app()->user->setFlash('success', 'Save successfully.');
        $this->refresh();
      }
    }
    
    $this->render('index', array(
      'model' => $model
    ));
  }
}